<template>
  <div class="app-container">
    <!-- <PageTitle title="订单列表" ref="pageTitle" v-model="listQuery.city" @onChange="changeCity" /> -->
    <div class="filter-container">
      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-plus"
        @click="$refs.edit.handleCreate()"
        >新增账号</el-button
      >
    </div>
    <div class="filter-container">
      <el-input
        style="width: 160px"
        class="filter-item"
        placeholder="请输入姓名"
        v-model="listQuery.name"
      ></el-input>
      <el-input
        style="width: 160px"
        class="filter-item"
        placeholder="请输入手机号"
        v-model="listQuery.mobile"
      ></el-input>
      <el-input
        style="width: 160px"
        class="filter-item"
        placeholder="请输入景区"
        v-model="listQuery.attraction_name"
      ></el-input>
      <el-input
        style="width: 160px"
        class="filter-item"
        placeholder="请输入角色"
        v-model="listQuery.role"
      ></el-input>

      <el-button class="filter-item" size="mini" plain @click="handleReset">重置</el-button>
      <el-button class="filter-item" size="mini" type="primary" @click="handleFilter"
        >查询</el-button
      >
    </div>
    <Table :data="list" :columns="columns" :loading="listLoading">
      <template v-slot:action>
        <el-table-column label="操作" minWidth="160" fixed="right">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="编辑" placement="top">
              <i class="el-icon-edit table-action" @click="$refs.edit.handleEdit(scope.row.id)"></i>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="删除" placement="top">
              <i class="el-icon-delete table-action" @click="handleDel(scope.row.id)"></i>
            </el-tooltip>
          </template>
        </el-table-column>
      </template>
    </Table>
    <div class="pagination-container">
      <pagination
        :total="count"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.size"
        @pagination="fetchData"
      />
    </div>
    <Edit ref="edit" />
  </div>
</template>

<script>
import { getList, del } from '@/api/account'
import Edit from './components/Edit'
export default {
  name: 'AccountIndex',
  components: { Edit },
  data() {
    return {
      list: null,
      count: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        size: 10,
        mobile: '',
        attraction_name: '',
        role: '',
        name: ''
      },
      columns: [
        {
          type: 'index',
          align: 'center',
          label: '序号',
          width: '50'
        },
        {
          label: '姓名',
          width: '120',
          prop: 'name',
          align: 'center'
        },
        {
          label: '手机号',
          width: '160',
          prop: 'mobile',
          align: 'center'
        },
        {
          label: '景区',
          width: '160',
          prop: 'attraction_str',
          showOverflowTooltip: true
        },

        {
          label: '角色',
          width: '120',
          prop: 'role_name',
          align: 'center'
        },
        {
          label: '创建时间',
          width: '160',
          prop: 'add_time'
        },
        {
          label: '最后登录时间',
          width: '160',
          prop: 'last_login_time'
        },
        {
          label: '操作',
          slot: 'action'
        }
      ]
    }
  },

  created() {
    this.fetchData()
  },
  mounted() {},
  methods: {
    // 获取数据
    fetchData() {
      this.listLoading = true
      getList(this.listQuery).then((res) => {
        this.list = res.data.list_data
        this.count = res.data.paging.count
        this.listLoading = false
      })
    },

    // 筛选
    handleFilter() {
      this.listQuery.page = 1
      this.fetchData()
    },
    /**
     * @description:
     * @return {*}
     */
    handleReset() {
      this.listQuery = {
        page: 1,
        size: 10,
        attraction_name: '',
        role: '',
        mobile: '',
        name: ''
      }
      this.fetchData()
    },
    /**
     * @description: 订单详情
     * @param {*} sn
     * @return {*}
     */
    handleDetail(sn, can_consume) {
      this.$router.push({ path: `/orders/detail/${sn}`, query: { can_consume } })
    },
    /**
     * @description: 删除
     */
    handleDel(uuid) {
      this.$confirm('确认删除该项目吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          del(uuid).then(() => {
            this.$notify({
              title: '成功',
              message: '删除成功',
              type: 'success'
            })
            this.fetchData()
          })
        })
        .catch(() => {})
    }
  }
}
</script>
<style scoped>
.filter-container {
  justify-content: flex-start !important;
  flex-wrap: wrap;
}
.el-button {
  margin-bottom: 5px;
  margin-left: 0;
  margin-right: 5px;
}
</style>
